// 简单的API测试脚本
// 运行: node test-api.js

const testProductsAPI = async () => {
    try {
        console.log('测试产品列表API...')
        const response = await fetch('http://localhost:3000/api/products')
        const data = await response.json()

        console.log('产品列表响应:', JSON.stringify(data, null, 2))

        if (data.success && data.data.products.length > 0) {
            const firstProduct = data.data.products[0]
            console.log('\n测试产品详情API...')
            console.log('测试产品ID:', firstProduct.id)

            const detailResponse = await fetch(`http://localhost:3000/api/products/${firstProduct.id}`)
            const detailData = await detailResponse.json()

            console.log('产品详情响应:', JSON.stringify(detailData, null, 2))
        } else {
            console.log('没有找到产品数据')
        }

    } catch (error) {
        console.error('API测试失败:', error)
    }
}

// 如果直接运行此文件
if (require.main === module) {
    testProductsAPI()
}

module.exports = { testProductsAPI }